+ bashly add completions --force
created src/lib/send_completions.sh

In order to enable completions in your script, create a command or a flag (for example: cli completions or cli --completions) that calls the send_completions function.

Your users can then run something like this to enable completions:

  $ eval "$(cli completions)"

+ bashly generate
creating user files in src
skipped src/completions_command.sh (exists)
skipped src/download_command.sh (exists)
skipped src/upload_command.sh (exists)
created ./cli
run ./cli --help to test your bash script
+ ./cli
cli - Sample application with bash completions

Usage:
  cli COMMAND
  cli [COMMAND] --help | -h
  cli --version | -v

Commands:
  completions   Generate bash completions
  download      Download a file
  upload        Upload a file

+ ./cli -h
cli - Sample application with bash completions

Usage:
  cli COMMAND
  cli [COMMAND] --help | -h
  cli --version | -v

Commands:
  completions   Generate bash completions
  download      Download a file
  upload        Upload a file

Options:
  --help, -h
    Show this help

  --version, -v
    Show version number

+ ./cli completions -h
cli completions

  Generate bash completions
  Usage: eval "$(cli completions)"

Usage:
  cli completions
  cli completions --help | -h

Options:
  --help, -h
    Show this help

+ ./cli completions
# cli completion                                           -*- shell-script -*-

# This bash completions script was generated by
# completely (https://github.com/bashly-framework/completely)
# Modifying it manually is not recommended

_cli_completions_filter() {
  local words="$1"
  local cur=${COMP_WORDS[COMP_CWORD]}
  local result=()

  # words the user already typed (excluding the command itself)
  local used=()
  if ((COMP_CWORD > 1)); then
    used=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
  fi

  if [[ "${cur:0:1}" == "-" ]]; then
    # Completing an option: offer everything (including options)
    echo "$words"

  else
    # Completing a non-option: offer only non-options,
    # and don't re-offer ones already used earlier in the line.
    for word in $words; do
      [[ "${word:0:1}" == "-" ]] && continue

      local seen=0
      for u in "${used[@]}"; do
        if [[ "$u" == "$word" ]]; then
          seen=1
          break
        fi
      done
      ((!seen)) && result+=("$word")
    done

    echo "${result[*]}"
  fi
}

_cli_completions() {
  local cur=${COMP_WORDS[COMP_CWORD]}
  local compwords=()
  if ((COMP_CWORD > 0)); then
    compwords=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
  fi
  local compline="${compwords[*]}"

  COMPREPLY=()

  case "$compline" in
    'download'*'--handler')
      while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "curl wget")" -- "$cur")
      ;;

    'upload'*'--user')
      while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A user -- "$cur")
      ;;

    'completions'*)
      while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--help -h")" -- "$cur")
      ;;

    'd'*'--handler')
      while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "curl wget")" -- "$cur")
      ;;

    'upload'*'-u')
      while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A user -- "$cur")
      ;;

    'download'*)
      while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A file -W "$(_cli_completions_filter "--force --handler --help -f -h")" -- "$cur")
      ;;

    'u'*'--user')
      while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A user -- "$cur")
      ;;

    'upload'*)
      while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A directory -A user -W "$(_cli_completions_filter "--help --password --user -h -p -u CHANGELOG.md README.md")" -- "$cur")
      ;;

    'u'*'-u')
      while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A user -- "$cur")
      ;;

    'd'*)
      while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A file -W "$(_cli_completions_filter "--force --handler --help -f -h")" -- "$cur")
      ;;

    'u'*)
      while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A directory -A user -W "$(_cli_completions_filter "--help --password --user -h -p -u CHANGELOG.md README.md")" -- "$cur")
      ;;

    *)
      while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--help --version -h -v completions d download u upload")" -- "$cur")
      ;;

  esac
} &&
  complete -F _cli_completions cli

# ex: filetype=sh
